package com.xdh.zzqh.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.xdh.zzqh.R
import com.xdh.zzqh.store.Product
import java.math.BigDecimal

class ProductParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val mLtiName: LabelTextInput
    private val mLtiStyle: LabelTextInput
    private val mLtiTy: LabelTextInput
    private val mLtiSpec: LabelTextInput
    private val mLtiDir: LabelTextInput
    private val mLtiPrice: LabelTextInput
    private val mLtiHands: LabelTextInput
    private val mLtiColor: LabelTextInput

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_product, this)

        mLtiName = view.findViewById(R.id.id_product_lti_name)
        mLtiStyle = view.findViewById(R.id.id_product_lti_style)
        mLtiTy = view.findViewById(R.id.id_product_lti_ty)
        mLtiSpec = view.findViewById(R.id.id_product_lti_spec)
        mLtiDir = view.findViewById(R.id.id_product_lti_dir)
        mLtiPrice = view.findViewById(R.id.id_product_lti_price)
        mLtiHands = view.findViewById(R.id.id_product_lti_hands)
        mLtiColor = view.findViewById(R.id.id_product_lti_color)
    }

    fun setProduct(product: Product) {
        mLtiStyle.setText(product.style)
        mLtiTy.setText(product.ty)
        mLtiSpec.setText(product.spec)
        mLtiDir.setText(product.dir)
        mLtiPrice.setText(product.price)
        mLtiHands.setText(product.hands)
        mLtiColor.setText(product.color)
        mLtiName.setText(product.name)
    }

    fun product(): Product {
        val style = mLtiStyle.text()
        val ty = mLtiTy.text()
        val spec = mLtiSpec.text()
        val dir = mLtiDir.text()
        val price = mLtiPrice.text()
        val hands = mLtiHands.text()
        val color = mLtiColor.text()
        val name = mLtiName.text()
        BigDecimal(price)
        return Product(name, ty, style, spec, dir, hands, color, price)
    }
}

